package com.jshop.config;

import com.jshop.api.interceptor.AdminInterceptor;
import com.jshop.api.interceptor.AuthorizationInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author jon
 * @date 2019-08-26 17:46
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    @Bean
    public AuthorizationInterceptor getAuthorizationInterceptor() {
        return new AuthorizationInterceptor();
    }
    @Bean
    public AdminInterceptor getAdminInterceptor() {
        return new AdminInterceptor();
    }
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //     /api/**
        registry.addInterceptor(getAuthorizationInterceptor()).addPathPatterns("/api/**")
                .excludePathPatterns("/swagger**").excludePathPatterns("/index").excludePathPatterns("/login");
        registry.addInterceptor(getAdminInterceptor()).addPathPatterns(("/admin/**")).addPathPatterns("/sys/**");
    }
}
